/* form-level styles */
.form-inline {
  display: flex;
  flex-wrap: wrap;
}

/* row-level styles */
.form-group {
  margin-bottom: var(--size-spacer);
  display: flex;
  .col-md-9,
  .col-md-3 {
    padding-left: 15px;
    padding-right: 15px;
  }
  &.form-group-inline {
    flex-direction: column;
    label {
      text-align: left;
    }
  }
}
.hide-label {
  label {
    display: none;
  }
  .form-group > .col-md-9 {
    max-width: 100%;
    flex: 0 0 100%;
    label {
      display: inline-block;
    }
  }
}
.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

/* non-input styles */
label {
  display: inline-flex;
  flex-direction: column;
  padding-top: 4px;
  padding-bottom: calc(0.375rem + 1px);
  margin-bottom: 0;
  font-size: inherit;
  text-align: right;
  user-select: none;
  font-weight: bold;
  .optional {
    font-weight: normal;
    color: var(--color-grey);
  }
  &.col-form-label.col-md-3 {
    padding-top: 8px;
    padding-right: 0;
  }
  &.inline-form-label {
    flex-direction: row;
    .optional {
      padding-left: 0.25rem;
      &:before {
        content: "(";
      }
      &:after {
        content: ")";
      }
    }
  }
}

small.form-text {
  font-size: inherit;
  margin-top: 0.25rem;
  display: block;
}
.invalid-feedback {
  font-size: 0.875rem;
  color: var(--color-danger);
  font-weight: normal;
  font-family: var(--font-family);
}

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

legend {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;

  padding: 0;
  font-size: 22px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 20px;
}

/* input level styles */

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  display: block;
  width: 100%;
  padding: 0.375rem 0.75rem;
  color: var(--color-text-input);
  caret-color: var(--color-text-input);
  font-size: 1rem;

  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  background-color: var(--color-bg);
  background-clip: padding-box;
  border: 1px solid var(--color-border);
  border-radius: var(--size-border-radius);
  transition:
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;

  &.small {
    height: calc(1.5em + 0.5rem + 2px);
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: 0.2rem;
  }

  &.is-valid {
    border-color: var(--color-success);
  }

  &[aria-invalid],
  &:user-invalid {
    border-color: var(--color-danger);
  }

  &:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 var(--color-text-input);
  }

  &:focus {
    border-color: var(--color-primary-light);
    outline: 0;
    box-shadow: var(--shadow-focus);
  }

  &::placeholder {
    color: var(--color-grey);
    opacity: 1;
  }

  &:disabled,
  &[readonly] {
    background-color: var(--color-grey-lightest);
    opacity: 1;
  }

  &::-webkit-datetime-edit {
    display: block;
    padding: 0;
  }
}

input[type="file"] {
  overflow: hidden;
  &:not(:disabled):not([readonly]) {
    cursor: pointer;
  }
}
::file-selector-button {
  margin-left: -6px;
  color: white;
  background-color: var(--color-secondary);
  pointer-events: none;
  border-width: 0;
  border-radius: var(--size-border-radius);
}
.form-group-inline {
  input[type="file"] {
    padding: 0.15rem 0.5rem;
  }
  ::file-selector-button {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    margin-top: -3px;
    margin-left: -5px;
    font-size: 0.875rem;
    border-radius: 0.2rem;
  }
}

input[type="checkbox"],
input[type="radio"] {
  -moz-appearance: none;
  -webkit-appearance: none;

  width: 24px;
  height: 24px;
  background: var(--color-offwhite);
  box-shadow: var(--shadow-checkbox);
  background-image: none !important;
  cursor: pointer;
  font-size: 1rem;

  &:checked {
    background: var(--color-primary);
    border: 4px solid var(--color-offwhite);
  }

  &:disabled,
  &[readonly] {
    filter: grayscale(100%);
    cursor: normal;
    pointer-events: none;
  }

  & + label {
    cursor: pointer;
    font-weight: normal;
    padding-left: 8px;
    vertical-align: super;
    font-size: 1rem;
    & ~ a .badge,
    & ~ .badge {
      /* This is primarily for the multi_languages_widget.html badges */
      vertical-align: super;
    }
  }
}

input[type="checkbox"] {
  border-radius: var(--size-border-radius);
}
input[type="radio"] {
  border-radius: 50%;
}
input[type="radio"] + label {
  line-height: 2;
}

.checkbox-group-legend {
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);

  span {
    background-color: var(--color-bg);
    padding-right: 0.5rem;
    position: relative;
    top: 0.5em;
  }
}

textarea {
  resize: vertical;
  height: auto;
  field-sizing: content;
}

select,
input[type="file"],
input [type="range"] {
  display: block;
  width: 100%;
}

select {
  padding: 0.375rem 2.25rem 0.375rem 0.75rem;
  background-color: var(--color-bg);
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='var(--color-text-input)' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
  word-wrap: normal;

  &[multiple],
  &[size]:not([size="1"]) {
    height: auto;
    background-image: none;
    padding-right: 0.75rem;
  }

  &:disabled {
    background-color: var(--color-grey-lighter);
  }
}

input[type="search"] {
  -webkit-appearance: textfield;
  outline-offset: -2px; /* Safari */
  height: fit-content;
  &.form-control.is-valid {
    border-color: var(--color-border);
  }
}
::-webkit-search-decoration {
  -webkit-appearance: none;
}

.bootstrap4-multi-input {
  margin: auto;
}

input[type="number"] {
  -moz-appearance: textfield !important;

  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
  }
}

::-webkit-file-upload-button,
::file-selector-button {
  -webkit-appearance: button;
}
::-webkit-datetime-edit-fields-wrapper,
::-webkit-datetime-edit-text,
::-webkit-datetime-edit-minute,
::-webkit-datetime-edit-hour-field,
::-webkit-datetime-edit-day-field,
::-webkit-datetime-edit-month-field,
::-webkit-datetime-edit-year-field,
::-webkit-color-swatch-wrapper {
  padding: 0;
}

.form-image-preview {
  max-width: 180px;
  background-size: 21px 21px;
  background-position:
    0 0,
    10px 10px;
  background-image:
    linear-gradient(
      45deg,
      #efefef 25%,
      rgb(239 239 239 / 0) 25%,
      rgb(239 239 239 / 0) 75%,
      #efefef 75%,
      #efefef
    ),
    linear-gradient(
      45deg,
      #efefef 25%,
      rgb(239 239 239 / 0) 25%,
      rgb(239 239 239 / 0) 75%,
      #efefef 75%,
      #efefef
    );
  border-radius: 6px;
  img {
    border-radius: 6px;
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow-light);
  }
}
.form-image-initial {
  display: inline-flex;
  & > a {
    padding-left: 0.25rem;
  }
  &:has(.form-image-clear) {
    padding-bottom: 0.5rem;
  }
  .form-image-clear {
    display: inline-flex;
    margin-left: 0.5rem;
    input[type="checkbox"] + label {
      padding-top: 0;
      padding-bottom: 0;
    }
  }
}

.input-group {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  width: 100%;

  & > input:not([type="checkbox"]):not([type="radio"]),
  & > select,
  & > button {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
    margin-bottom: 0;

    & + & {
      margin-left: -1px;
    }

    &:focus {
      z-index: 3;
    }
    &:not(:first-child) {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
    &:not(:last-child) {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
  }
}

.input-group-prepend,
.input-group-append {
  display: flex;

  button {
    position: relative;
    z-index: 2;

    &:focus {
      z-index: 3;
    }
  }

  button + button,
  button + .input-group-text,
  .input-group-text + .input-group-text,
  .input-group-text + button {
    margin-left: -1px;
  }
}

.input-group-prepend {
  margin-right: -1px;
}
.input-group-append {
  margin-left: -1px;
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  margin-bottom: 0;
  color: var(--color-text-input);
  text-align: center;
  white-space: nowrap;
  background-color: var(--color-grey-lighter);
  border: 1px solid var(--color-border);
  border-radius: var(--size-border-radius);
}

.input-group > .input-group-prepend > button,
.input-group > .input-group-prepend > .input-group-text,
.input-group:not(.has-validation)
  > .input-group-append:not(:last-child)
  > button,
.input-group:not(.has-validation)
  > .input-group-append:not(:last-child)
  > .input-group-text,
.input-group.has-validation
  > .input-group-append:nth-last-child(n + 3)
  > button,
.input-group.has-validation
  > .input-group-append:nth-last-child(n + 3)
  > .input-group-text,
.input-group
  > .input-group-append:last-child
  > button:not(:last-child):not(.dropdown-toggle),
.input-group
  > .input-group-append:last-child
  > .input-group-text:not(:last-child) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group > .input-group-append > button,
.input-group > .input-group-append > .input-group-text,
.input-group > .input-group-prepend:not(:first-child) > button,
.input-group > .input-group-prepend:not(:first-child) > .input-group-text,
.input-group > .input-group-prepend:first-child > button:not(:first-child),
.input-group
  > .input-group-prepend:first-child
  > .input-group-text:not(:first-child) {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.labelless-password-input-form {
  margin-left: auto;
  margin-right: auto;

  .form-group {
    flex-direction: column;
  }

  input.password_strength,
  input.password_confirmation {
    height: 100%;
    display: block;
    width: 100%;
    flex-grow: 1;
  }
}
input.password_strength {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  &:focus {
    border-bottom: 0;
    + .password-progress .password-progress-bar {
      border: #89d6b8 2px solid;
      border-top: 0;
    }
  }
}

#auth-form {
  flex-direction: row;
  .form-group {
    flex-direction: column;
  }
  .auth-form-block {
    margin: 12px;
    flex-basis: 100%;
  }
  .optional {
    display: none;
  }
}

.hide-optional .optional {
  display: none;
}

.password-input-form,
.labelless-password-input-form {
  p.text-muted {
    font-size: 80%;
    padding-top: 2px;
    padding: 0;
    margin-bottom: 0;
    color: var(--color-text-lighter);
  }

  .password-progress {
    margin-top: 0 !important;

    .password-progress-bar {
      height: 4px;
      margin-bottom: 0 !important;
      border-bottom-left-radius: 4px;
      border-bottom-right-radius: 4px;
      border-top-left-radius: 0px;
      border-top-right-radius: 0px;
    }
  }
}

.password_strength_info {
  margin-bottom: 0;
}

.submit-group {
  display: flex;
  justify-content: space-between;
  flex-grow: 1;
  flex-wrap: wrap;
  background-color: var(--color-grey-pale);
  padding: 16px;
  margin-bottom: 16px;

  button {
    align-self: flex-end;

    i.fa {
      padding-right: 8px;
    }
  }
}

.markdown-wrapper {
  textarea {
    min-height: 140px;
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
  .markdown-preview {
    border: 1px solid #ced4da;
    border-top: none;
    border-bottom-left-radius: var(--size-border-radius);
    border-bottom-right-radius: var(--size-border-radius);
    min-height: 140px;
    padding: 0.375rem 0.75rem;
    overflow-y: auto;
    width: auto;
    background: var(--color-bg);
    color: var(--color-text-input);
  }
}
.markdown-nav[role="tablist"] {
  margin-bottom: 0;
  input[type="radio"][role="tab"] {
    & + label {
      line-height: 1.4;
    }
    &:checked + label {
      border: 1px solid var(--color-border);
      border-radius: var(--size-border-radius) var(--size-border-radius) 0 0;
      border-bottom: 1px solid white !important;
    }
  }
}

/* choices.js / enhanced selects */
.choices {
  width: 100%;
  margin-bottom: 0;

  .choices__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 2px 5px;
    color: var(--color-text-input);
    caret-color: var(--color-text-input);
    background-color: var(--color-bg);
    background-clip: padding-box;
    border: 1px solid var(--color-border);
    border-radius: var(--size-border-radius);
    min-height: 2.5rem;
    transition:
      border-color 0.15s ease-in-out,
      box-shadow 0.15s ease-in-out;
    .choices__item {
      font-size: 1rem;
      display: inline-flex;
      align-items: center;
      border-radius: var(--size-border-radius);
      color: var(--color-text-input);
      background-color: var(--color-bg);
      border: 0;
      margin: 2px;
      padding-right: 5px;

      &.choices__item--selectable {
        button {
          color: var(--color-danger) !important;
        }
      }

      button {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        margin: 0;
        padding: 0;
        width: 18px;
        height: 22px;
        color: var(--color-text-input);
        font-size: 1rem;
        font-weight: bold;
        text-indent: 0;
        background-image: none;
      }
    }

    &:has(input:focus) {
      border-color: var(--color-primary-light);
      outline: 0;
      box-shadow: var(--shadow-focus);
    }
  }

  &[data-type*="select-one"] {
    .choices__inner {
      padding-bottom: 0;
    }
    &:after {
      border-color: var(--color-grey) transparent transparent;
    }
    &.is-open:after {
      border-color: transparent transparent var(--color-grey);
    }
  }
  .has-no-choices {
    display: none;
  }

  input[type="search"] {
    height: 28px !important;
    font-size: 1rem;
    display: inline;
    padding: 0;
    margin-left: 8px;
    margin-bottom: 0;
    height: calc(1.5em + 0.5rem + 2px);
    &,
    &:focus,
    &:active,
    &:focus-visible {
      border: none;
      box-shadow: none;
    }
  }
  .choices__list.choices__list--multiple {
    .choices__item {
      padding: 2px 5px 2px 2px;
      box-shadow: var(--shadow-checkbox);
      &.choice-item-color:before {
        margin-left: 5px;
      }
    }
  }
  .choices__list.choices__list--dropdown {
    z-index: 500;
    border-bottom-right-radius: var(--size-border-radius);
    border-bottom-left-radius: var(--size-border-radius);
    border-color: var(--color-border);
    /* Make the corner radius look slightly less silly */
    margin-top: -2px;
    margin-bottom: -2px;

    .choices__item {
      font-size: 1rem;
      color: var(--color-text-input);

      &.choice-item-color:before {
        margin-right: 5px;
      }

      .choice-item-description {
        color: var(--color-grey);
        font-style: italic;
        font-size: 0.8rem;
      }
    }
  }

  .choices__item.choice-item-color:before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--choice-color);
    margin-top: 2px;
  }
  .choices__item.choice-item-color:not([data-deletable]):before {
    margin-right: 5px;
    margin-top: 2px;
  }
}

.submit-group .choices {
  align-self: flex-start;
}

/* media queries */

@media (max-width: 768px) {
  .submit-group {
    flex-direction: column;
    button,
    .btn {
      width: 100%;
      margin-bottom: 8px;
    }
  }
}
